﻿using Automatonymous;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace AutomatonymousTest
{
    class Relationship
    {
        public State CurrentState { get; set; }
        public string Name { get; set; }
    }

    class RelationshipStateMachine :
        AutomatonymousStateMachine<Relationship>
    {
        public RelationshipStateMachine()
        {


            Event(() => Hello);
            Event(() => PissOff);
            Event(() => Introduce);

            // Explicit definition of the states.
            State(() => Friend);
            State(() => Enemy);
            Initially(
                When(Hello).Then(p =>
                {
                    Console.WriteLine("Sayhello");
                    Console.WriteLine("p:"+p.ToString());
                })
                    .TransitionTo(Friend),
                When(PissOff)
                    .TransitionTo(Enemy),
                When(Introduce)
                    .Then(ctx =>
                    {
                        Thread.CurrentThread.Join(3000);
                        Console.WriteLine(ctx.Instance.CurrentState);

                        Console.WriteLine(ctx.Instance.Name);
                        Console.WriteLine(ctx.Data.Name);

                        ctx.Instance.Name = ctx.Data.Name;
                        Console.WriteLine(ctx.Instance.Name);
                    }
                    )
                    .TransitionTo(Friend)
                    
            );
        }

        public State Friend { get; private set; }
        public State Enemy { get; private set; }

        public Event Hello { get; private set; }
        public Event PissOff { get; private set; }
        public Event<Person> Introduce { get; private set; }
    }

    class Person
    {
        public string Name { get; set; }
    }
}
